import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* Router Modules */

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/console',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/console/console'),
        name: 'console',
        meta: { title: '调用链监控', icon: 'nested' }
      }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: 'noredirect',
    name: 'Charts',
    meta: { title: '统计报表', icon: 'chart' },
    children: [
      {
        path: 'statError',
        component: () => import('@/views/stat/statError'),
        name: 'statError',
        meta: { title: '错误率', noCache: true }
      },
      {
        path: 'statPercent',
        component: () => import('@/views/stat/statPercent'),
        name: 'statPercent',
        meta: { title: '百分位', noCache: true }
      },
      {
        path: 'statDependency',
        component: () => import('@/views/stat/statDependency'),
        name: 'statDependency',
        meta: { title: '服务依赖', noCache: true }
      },
      {
        path: 'statSunburst',
        component: () => import('@/views/stat/statSunburst'),
        name: 'StatSunburst',
        meta: { title: '旭日图', noCache: true }
      },
      {
        path: 'statUnion',
        component: () => import('@/views/stat/statUnion'),
        name: 'statUnion',
        meta: { title: '高峰期耗时分析', noCache: true }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: 'noredirect',
    name: 'Setting',
    meta: { title: '系统配置', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'enumSetting',
        component: () => import('@/views/settings/enumSettings'),
        name: 'EnumSetting',
        meta: {
          title: '枚举配置', roles: ['admin']
        }
      },
      {
        path: 'platformSettings',
        component: () => import('@/views/settings/platformSettings'),
        name: 'PlatformSetting',
        meta: {
          title: '平台配置', roles: ['admin']
        }
      },
      {
        path: 'userSettings',
        component: () => import('@/views/settings/userSettings'),
        name: 'UserSetting',
        meta: {
          title: '用户配置', roles: ['admin']
        }
      },
      {
        path: 'alertSettings',
        component: () => import('@/views/settings/alertRuleSettings'),
        name: 'AlertSettings',
        meta: {
          title: '报警配置', roles: ['admin']
        }
      },
      {
        path: 'alertLog',
        component: () => import('@/views/settings/alertLog'),
        name: 'AlertLog',
        meta: {
          title: '报警日志', roles: ['admin']
        }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]
